package com.qf.servlet;

import com.qf.service.UserService;
import com.qf.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author AzureSky_X
 * @Date 2021/1/12 19:25
 * @Version 1.0
 * 删除用户
 */
@WebServlet("/deleteUser")
public class DeleteUserController extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id=Integer.valueOf(request.getParameter("id"));
        UserService userService=new UserServiceImpl();
        userService.deleteUser(id);
        //删除完数据之后要再次查询，要用重定向，否则地址不变容易再次删除数据
        response.sendRedirect(request.getContextPath()+"/user/list");

    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}